package am.ui;

import am.bll.BookEditor;
import am.bll.BookReader;
import am.bll.entity.AccountBook;
import am.core.R;
import am.exception.DatabaseException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class BookDetailActivity extends Activity
{
    private static BookReader bookReader;
    private static BookEditor bookEditor;

    public static void setBookReader(BookReader bookReader)
    {
        BookDetailActivity.bookReader = bookReader;
    }

    public static void setBookEditor(BookEditor bookEditor)
    {
        BookDetailActivity.bookEditor = bookEditor;
    }

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.book_detail);

        // 调试用
        AccountBook book;
        try
        {
            book = bookReader.readAllBooks().get(0);
        }
        catch (DatabaseException e)
        {
            // 报错
            return;
        }

        // 绑定到前端
        TextView createTimeView = (TextView) findViewById(R.id.bdCreateTime);
        TextView lastEditTimeView = (TextView) findViewById(R.id.bdLastEditTime);
        TextView nameView = (TextView) findViewById(R.id.bdName);
        TextView remarkView = (TextView) findViewById(R.id.bdRemark);
        TextView totalView = (TextView) findViewById(R.id.bdTotal);

        createTimeView.setText(book.getCreateTime().toString());
        lastEditTimeView.setText(book.getLastEditTime().toString());
        nameView.setText(book.getName());
        // remarkView.setText();
        totalView.setText(book.getTotal().toString());

    }
}
